package com.wongoing.sys.viewmodel;

import java.util.HashMap;
import java.util.Map;

import org.apache.poi.ss.formula.functions.T;

import com.wongoing.base.Json;

/**
 * <p> Title: JsonResult </p>
 * <p> Description:json 返回类</p>
 * <p> Company: mesnac</p>
 * @author wuzq
 * @date 2017-5-8下午10:48:15
 * @retrun
 */
public class JsonResult {
	
	/**
	 * <p>Title: jsonValidateReturn</p>
	 * <p>Description: 验证返回json</p>
	 * <p>Company: mesnac</p>
	 * @param resultFlag
	 * @return
	 * @author wuzq
	 * @date 2017-5-10下午8:33:00
	 * @retrun
	 */
	public static Map<String,Object> jsonValidateReturn(boolean resultFlag){
		Map<String,Object> jsonObj = new HashMap<String, Object>();
		if(resultFlag){
			jsonObj.put("ok", "通过验证");
		}else{
			jsonObj.put("error", "验证失败");
		}
		return jsonObj;
	}
	
	/**
	 * <p>Title: </p>
	 * <p>Description:验证返回json,消息自定义</p>
	 * <p>Company: mesnac</p>
	 * @param resultFlag
	 * @param msg
	 * @return
	 * @author wuzq
	 * @date 2017-5-10下午8:33:25
	 * @retrun
	 */
	public static Map<String,Object> jsonValidateReturn(boolean resultFlag,String msg){
		Map<String,Object> jsonObj = new HashMap<String, Object>();
		if(resultFlag){
			jsonObj.put("ok", msg);
		}else{
			jsonObj.put("error", msg);
		}
		return jsonObj;
	}
	
	/**
	 * <p>Title: jsonReturn</p>
	 * <p>Description:根据状态码返回json map</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode
	 * @return
	 * @author wuzq
	 * @date 2017-5-9上午8:57:28
	 * @retrun
	 */
	public static Map<String, Object> jsonReturn(int statusCode) {
		Map<String, Object> jsonObj = setJsonObj(statusCode, null);
		jsonObj.put("closeCurrent", true);
		return jsonObj;
	}

	/**
	 * <p>Title: jsonReturn</p>
	 * <p>Description:根据状态码和close current返回json map</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode
	 * @param closeCurrent
	 * @return
	 * @author wuzq
	 * @date 2017-5-9上午9:00:27
	 * @retrun
	 */
	public static Map<String, Object> jsonReturn(int statusCode, boolean closeCurrent) {
		Map<String, Object> jsonObj = setJsonObj(statusCode, null);
		jsonObj.put("closeCurrent", closeCurrent);
		return jsonObj;
	}
	
	/**
	 * <p>Title: jsonReturn</p>
	 * <p>Description:根据状态码和信息返回json map</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode
	 * @param msg
	 * @return
	 * @author wuzq
	 * @date 2017-5-9上午9:03:21
	 * @retrun
	 */
	public static Map<String, Object> jsonReturn(int statusCode, String msg) {
		Map<String, Object> jsonObj = setJsonObj(statusCode, msg);
		jsonObj.put("closeCurrent", true);
		return jsonObj;
	}

	/**
	 * <p>Title: jsonReturn</p>
	 * <p>Description: 根据状态码、信息和close current返回json map</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode
	 * @param msg
	 * @param closeCurrent
	 * @return
	 * @author wuzq
	 * @date 2017-5-9上午9:03:51
	 * @retrun
	 */
	public static Map<String, Object> jsonReturn(int statusCode, String msg,
			boolean closeCurrent) {
		Map<String, Object> jsonObj = setJsonObj(statusCode, msg);
		jsonObj.put("closeCurrent", closeCurrent);
		return jsonObj;
	}

	/**
	 * <p>Title: jsonReturn</p>
	 * <p>Description: 多信息返回</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode 状态码
	 * @param msg 返回信息
	 * @param tabid 标签ID
	 * @param closeCurrent
	 * @param forward
	 * @param forwardConfirm
	 * @return
	 * @author wuzq
	 * @date 2017-5-9上午9:04:38
	 * @retrun
	 */
	public static Map<String, Object> jsonReturn(int statusCode, String msg,
			String tabid, boolean closeCurrent, String forward,
			String forwardConfirm) {
		Map<String, Object> jsonObj = setJsonObj(statusCode, msg);
		jsonObj.put("tabid", tabid);
		jsonObj.put("closeCurrent", closeCurrent);
		jsonObj.put("forward", forward);
		jsonObj.put("forwardConfirm", forwardConfirm);
		return jsonObj;
	}

	/**
	 * <p>Title: jsonReturn</p>
	 * <p>Description: 多信息返回</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode 状态码
	 * @param msg 返回信息
	 * @param tabid 标签ID
	 * @param closeCurrent
	 * @param forward
	 * @param forwardConfirm
	 * @return
	 * @author wuzq
	 * @date 2017-5-9上午9:04:38
	 * @retrun
	 */
	public static Map<String, Object> jsonReturn(int statusCode, String msg, String tabid) {
		Map<String, Object> jsonObj = setJsonObj(statusCode, msg);
		jsonObj.put("tabid", tabid);
		jsonObj.put("closeCurrent", true);
		jsonObj.put("forward", "");
		jsonObj.put("forwardConfirm", "");
		return jsonObj;
	}
	
	/**
	 * <p>Title: jsonReturn</p>
	 * <p>Description: 多信息返回</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode 状态码
	 * @param msg 返回信息
	 * @param tabid 标签ID
	 * @param closeCurrent
	 * @param forward
	 * @param forwardConfirm
	 * @return
	 * @author wuzq
	 * @date 2017-5-9上午9:04:38
	 * @retrun
	 */
	public static Map<String, Object> jsonReturnErr(String msg) {
		Map<String, Object> jsonObj = setJsonObj(300, msg);
		jsonObj.put("tabid", "");
		jsonObj.put("closeCurrent", false);
		return jsonObj;
	}

	/**
	 * <p>Title: setJsonObj</p>
	 * <p>Description:状态码判断公用方法</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode
	 * @param msg
	 * @return
	 * @author wuzq
	 * @date 2017-5-9上午10:15:31
	 * @retrun
	 */
	private static Map<String, Object> setJsonObj(int statusCode, String msg) {
		Map<String, Object> jsonObj = new HashMap<String, Object>();
		switch (statusCode) {
		case 200:
			jsonObj.put("statusCode", "200");
			jsonObj.put("message", msg == null ? "操作成功" : msg);
			break;
		case 300:
			jsonObj.put("statusCode", "300");
			jsonObj.put("message", msg == null ? "操作失败" : msg);
			break;
		}
		return jsonObj;
	}
	
	/**
	 * <p>Title: jsonWsReturn</p>
	 * <p>Description:状态码判断公用方法</p>
	 * <p>Company: mesnac</p>
	 * @param statusCode	访问状态
	 * @param msg			提示消息
	 * @param result		返回数据
	 * @return
	 * @author Kane
	 * @date 2017-7-25 14:16:57
	 * @retrun
	 */
	public static Map<String, Object> jsonWsReturn(int state, String msg ,Object result) {
		Map<String, Object> jsonObj = new HashMap<String, Object>();
		switch (state) {
		case 0:
			jsonObj.put("state", "0");
			jsonObj.put("statusCode", "200");
			jsonObj.put("message", msg == null ? "接口访问成功" : msg);
			jsonObj.put("result", result == null ? "" : result);
			break;
		case 1:
			jsonObj.put("state", "1");
			jsonObj.put("statusCode", "300");
			jsonObj.put("message", msg == null ? "接口访问失败" : msg);
			jsonObj.put("result", result == null ? "" : result);
			break;
		}
		return jsonObj;
	}
	/*public static  Json<T> jsonWsSuccess(Json<T> json){
		return new json("提示信息", "接口访成功", true, 200);
	}
	public static Json<T> jsonWsSuccess(String title,String msg){
		return new Json<T>(title, msg, true, 200);
	}
	public static Json<T> jsonWsSuccess(String msg){
		return new Json<T>("提示信息", msg, true, 200);
	}
	public static Json<T> jsonWsSuccess(int statusCodes){
		return new Json<T>("提示信息", "接口访成功", true, statusCodes);
	}

	public static Json<T> jsonWsFail(){
		return new Json<T>();
	}
	public static Json<T> jsonWsFail(String title,String msg){
		return new Json<T>(title, msg, false, 300);
	}
	public static Json<T> jsonWsFail(String msg){
		return new Json<T>("提示信息", msg, false, 300);
	}
	public static Json<T> jsonWsFail(int statusCodes){
		return new Json<T>("提示信息", "接口访失败", false, statusCodes);
	}*/

}
